home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: brianmcg@interaccess.com (Brian V. McGroarty)
- Newsgroups: comp.lang.c,comp.lang.c.moderated
- Subject: Re: Multiple Indirection (Pointer Arithmatic)
- Date: 24 Mar 1996 11:40:34 -0600
- Organization: InterAccess, Chicago's best Internet Service Provider
- Sender: clc@solutions.solon.com
- Approved: clc@solutions.solon.com
- Message-ID: <4j41ei$nfa@solutions.solon.com>
- References: <4j06ig$7q8@solutions.solon.com>
- NNTP-Posting-Host: solutions.solon.com
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
-
- R Ghosh-Roy wrote:
- >I have three arrays (A,B,C) of structures and each structure has its own
- >set
- >of fields. In structure A, one particular field Ab points to structure B. B
- >has a field Bc which points to C and C has a field named Cd. I need to look
- >for Cd for each A. Can I use some kind of clever pointer arithmatic to get
- >to Cd for each A? Or, is there a cleverer way?
-
-
- >Note: 3 arrays of structures A,B and C and only one field relates elements
- > of each array, ie, Ab relates to an element within an array of Bs and
- > Bc relates to an element within an array of Cs. These are dynamically
- > assigned.
-
-
- [...]
-
- >I was thinking of using sizeof and offsetof expressions.
-
-
- There's no need for anything too strange. Since the member of A which points
- to B should be of type "struct B *" the compiler already knows what you will
- be pointing to. Consider something like the following:
-
- struct C *newCPointer;
- newCPointer= structSetA[ 5 ].Ab->Bc;
-
-
- To avoid obfuscated code, you could use the following. Any good compiler
- should generate the same code for the above as for the below:
-
- struct B *newBPointer;
- struct C *newCPointer;
- newBPointer= structSetA[ 5 ].Ab;
- newCPointer= newBPointer->Bc;
-
-
-
- ---
- Brian Valters McGroarty -- brianmcg@bix.com
- phone/fax (847) 439-7714
-